﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;

/// <summary>
/// Summary description for clsProductCategoryRecord
/// </summary>
public class clsProductCategoryRecord
{
    #region MEMBER VARIABLES

        private int m_iProductCategoryID;
        private DateTime m_dtAdded;
        private int m_iAddedBy;
        private DateTime m_dtEdited;
        private int m_iEditedBy;
        private string m_strCategoryName;
        private string m_strCategoryType;
        private string m_strCategoryDescription;
        private bool m_bIsActive;
        protected clsUser m_clsUser; 
    
    #endregion

    #region PROPERTIES

    public int iProductCategoryID
    {
        get
        {
            return m_iProductCategoryID;
        }
    }

    public DateTime dtAdded
    {
        get
        {
            return m_dtAdded;
        }
        set
        {
            m_dtAdded = value;
        }
    }

    public int iAddedBy
    {
        get
        {
            return m_iAddedBy;
        }
        set
        {
            m_iAddedBy = value;
        }
    }

    public DateTime dtEdited
    {
        get
        {
            return m_dtEdited;
        }
        set
        {
            m_dtEdited = value;
        }
    }

    public int iEditedBy
    {
        get
        {
            return m_iEditedBy;
        }
        set
        {
            m_iEditedBy = value;
        }
    }

    public String strProductCategoryName
    {
        get
        {
            return m_strCategoryName;
        }
        set
        {
            m_strCategoryName = value;
        }
    }

    public String strProductCategoryType
    {
        get
        {
            return m_strCategoryType;
        }
        set
        {
            m_strCategoryType = value;
        }
    }

    public String strCategoryDescription
    {
        get
        {
            return m_strCategoryDescription;
        }
        set
        {
            m_strCategoryDescription = value;
        }
    }

    public bool bIsActive
    {
        get
        {
            return m_bIsActive;
        }
        set
        {
            m_bIsActive = value;
        }
    }

    #endregion

    #region CONSTRUCTORS

    public clsProductCategoryRecord(clsUser clsUser)
    {
        m_clsUser = clsUser;
        m_iProductCategoryID = 0;
    }

    public clsProductCategoryRecord(clsUser clsUser, int iProductCategoryID)
        : this(clsUser)
    {
        m_iProductCategoryID = iProductCategoryID;
        GetData();
    }

    #endregion

    #region PUBLIC METHODS

    public virtual void Update()
    {
        try
        {
            clsCommonFunctions clsCommonFunctions = new clsCommonFunctions();
            if (iProductCategoryID == 0)
            {
                //### Add
                m_iProductCategoryID = (int)DataConnection.GetDataObject().ExecuteScalar("spProductCategoryInsert '" +
                    this.m_dtAdded + "'," + this.m_iAddedBy + " ,'" + this.m_dtEdited + "', " + this.m_iEditedBy + 
                    ", '" + clsCommonFunctions.escapeChar(this.m_strCategoryName) + 
                    "', '" + clsCommonFunctions.escapeChar(this.m_strCategoryType) +
                    "', '" + clsCommonFunctions.escapeChar(this.m_strCategoryDescription) +  "'");
            }
            else
            {
                //### Update
                DataConnection.GetDataObject().Execute("spProductCategoryUpdate " + this.m_iProductCategoryID +
                    this.m_dtAdded + "'," + this.m_iAddedBy + " ,'" + this.m_dtEdited + "', " + this.m_iEditedBy +
                    ", '" + clsCommonFunctions.escapeChar(this.m_strCategoryName) +
                    "', '" + clsCommonFunctions.escapeChar(this.m_strCategoryType) +
                    "', '" + clsCommonFunctions.escapeChar(this.m_strCategoryDescription) + "'");
            }
        }
        catch (Exception ex)
        {
            clsErrorLog.LogError(ex, this, m_clsUser, 95);
            throw ex;
        }
    }

    public virtual void Delete()
    {
        DataConnection.GetDataObject().Execute("spProductCategoryDelete " + this.m_iProductCategoryID);
    }

    #endregion

    #region PROTECTED METHODS

    protected virtual void GetData()
    {
        try
        {
            DataSet dtsData;
            dtsData = new DataSet();
            dtsData = DataConnection.GetDataObject().GetData("Data", "spProductCategoryGetRecord " + this.m_iProductCategoryID);
            m_dtAdded = Convert.ToDateTime(dtsData.Tables["Data"].Rows[0]["dtAdded"]);
            m_iAddedBy = Convert.ToInt32(dtsData.Tables["Data"].Rows[0]["iAddedBy"]);
            m_dtEdited = Convert.ToDateTime(dtsData.Tables["Data"].Rows[0]["dtEdited"]);
            m_iEditedBy = Convert.ToInt32(dtsData.Tables["Data"].Rows[0]["iEditedBy"]);
            m_strCategoryName = dtsData.Tables["Data"].Rows[0]["strCategoryName"].ToString();
            m_strCategoryType = dtsData.Tables["Data"].Rows[0]["strCategoryType"].ToString();
            m_strCategoryDescription = dtsData.Tables["Data"].Rows[0]["strCategoryDescription"].ToString();
            //m_strDubblePrice = dtsData.Tables["Data"].Rows[0]["strDubblePrice"].ToString();
            //m_strPathToImage = dtsData.Tables["Data"].Rows[0]["strPathToImage"].ToString();
            m_bIsActive = Convert.ToBoolean(dtsData.Tables["Data"].Rows[0]["bIsActive"]);

        }
        catch (Exception ex)
        {
            clsErrorLog.LogError(ex, this, m_clsUser, 95);
            throw ex;
        }
    }

    #endregion
}